package Com.javaserver.servlet;

import Com.javaserver.bean.admid;
import Com.javaserver.dao.addmiserver;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

@WebServlet("/admidadd")
public class admiadd extends HttpServlet {
    addmiserver a=new addmiserver();

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doPost(req,resp);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.setCharacterEncoding("UTF-8");
        resp.setCharacterEncoding("UTF-8");
        admid ad=new admid();

        ad.setAccount(req.getParameter("name"));
        ad.setPassword(req.getParameter("month"));
        if (a.admidadd(ad) == null){
            req.getSession().setAttribute("msg", "添加失败");
            resp.sendRedirect(req.getContextPath() + "/Addsystem.jsp");
        }else {
            List<admid> list = a.admi(1);
            req.getSession().setAttribute("admi", list);
            req.getSession().setAttribute("msg", "添加成功");
            resp.sendRedirect(req.getContextPath() + "/admi");
        }

    }
}
